package cn.rengy.web.framework.util;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.rengy.web.framework.principal.Identity;
import cn.rengy.web.framework.principal.WechatIdentity;

public class GetSessionUtils{
	
	private static Logger logger = LoggerFactory.getLogger(GetSessionUtils.class);
	
	public static boolean isLogin(){
		Subject subject = SecurityUtils.getSubject();
        return subject.isAuthenticated();
	}
	public static Long getUserId(){
		Subject subject = SecurityUtils.getSubject();
		if(subject.isAuthenticated()) {
			Identity identity=(Identity)subject.getPrincipal();
			return identity.getUserid();
		}
		return null;
	}
	
	public static String getOpenid(){
		Subject subject = SecurityUtils.getSubject();
		if(subject.isAuthenticated()) {
			Identity identity=(Identity)subject.getPrincipal();
			if(identity instanceof WechatIdentity) {
				return ((WechatIdentity)identity).getOpenid();
			}
		}
		return null;
	}
}
